package com.zhanghaijun.createCode.jdk.annotation.inherited;

import com.zhanghaijun.createCode.util.PrintUtil;
import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * Created by zhanghaijun on 15/7/22.
 */
public class ChildClass extends SuperClass {


    @Override
    public void abstractMethod() {

    }


    @Override
    public void overrideMethod() {
        super.overrideMethod();
    }

    @Test
    public void test() throws Exception{
        Class<ChildClass> cls= ChildClass.class;
        if(cls.isAnnotationPresent(Debug.class)){
            Debug debug = cls.getAnnotation(Debug.class);
            PrintUtil.println("子类继承父类的注解:" + debug.name() + "|" + debug.value());
        }else{
            PrintUtil.println("子类没有继承父类的注解");
        }

        Method abstractMethod = cls.getMethod("abstractMethod", new Class[]{});
        if(abstractMethod.isAnnotationPresent(Debug.class)){
            Debug debug = abstractMethod.getAnnotation(Debug.class);
            PrintUtil.println("子类abstractMethod继承父类abstractMethod的注解:" + debug.name() + "|" + debug.value());
        }else{
            PrintUtil.println("子类abstractMethod没有继承父类abstractMethod的注解");
        }

        Method notOverrideMethod = cls.getMethod("notOverrideMethod", new Class[]{});
        if(notOverrideMethod.isAnnotationPresent(Debug.class)){
            Debug debug = notOverrideMethod.getAnnotation(Debug.class);
            PrintUtil.println("子类notOverrideMethod继承父类notOverrideMethod的注解:" + debug.name() + "|" + debug.value());
        }else{
            PrintUtil.println("子类notOverrideMethod没有继承父类notOverrideMethod的注解");
        }


        Method overrideMethod = cls.getMethod("overrideMethod", new Class[]{});
        if(overrideMethod.isAnnotationPresent(Debug.class)){
            Debug debug = overrideMethod.getAnnotation(Debug.class);
            PrintUtil.println("子类overrideMethod继承父类overrideMethod的注解:" + debug.name() + "|" + debug.value());
        }else{
            PrintUtil.println("子类overrideMethod没有继承父类overrideMethod的注解");
        }
    }

}
